package com.data.service.statistics.impl;

import com.data.domain.statistics.Netresult;
import com.data.domain.statistics.NetresultCriteria;
import com.data.mapper.statistics.NetresultMapper;
import com.data.model.NetResultPrint;
import com.data.model.ReportModel;
import com.data.model.StatisticsModel;
import com.data.service.statistics.NetresultService;
import com.data.utill.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service(value = "netresultService")
public class NetresultServiceImpl implements NetresultService {

    @Autowired
    private NetresultMapper netresultMapper;

    /**
     * 全查询
     * @param statisticsModel
     * @return
     */
    @Override
    public List<Netresult> getNetresult(StatisticsModel statisticsModel){
        NetresultCriteria netresultCriteria=new NetresultCriteria();
        NetresultCriteria.Criteria criteria=netresultCriteria.createCriteria();
        if(StringUtils.isNoNullString(statisticsModel.getStart())){
            criteria.andWorkdateGreaterThan(StringUtils.cutDateStr(statisticsModel.getStart()));
        }
        if(StringUtils.isNoNullString(statisticsModel.getEnd())){
            criteria.andWorkdateLessThan(StringUtils.cutDateStr(statisticsModel.getEnd()));
        }
        if(StringUtils.isNoNullString(statisticsModel.getCode())){
            criteria.andNetroundEqualTo(Short.parseShort(statisticsModel.getCode()));
        }
        netresultCriteria.setOrderByClause("workdate desc");
        return netresultMapper.selectByExample(netresultCriteria);
    }

    /**
     * 打印报表
     * @return
     */
    public List<NetResultPrint> netResultPrints(){
        List<NetResultPrint> data = new ArrayList<>();
        NetresultCriteria netresultCriteria=new NetresultCriteria();
        netresultCriteria.createCriteria().getAllCriteria();

        List<Netresult> list = netresultMapper.selectByExample(netresultCriteria);

        for(Netresult netresult:list){
            NetResultPrint tmp = new NetResultPrint();
            tmp.setBankname(netresult.getBankcode());
            tmp.setCcount(netresult.getCcount().toString());
            tmp.setDcount(netresult.getDcount().toString());
            tmp.setCamount(netresult.getCamount().toString());
            tmp.setDamount(netresult.getDamount().toString());
            data.add(tmp);
        }
        return data;
    }
}
